package com.example.backend.controller;


import com.example.backend.pojo.Complain;
import com.example.backend.pojo.Result;

import com.example.backend.service.ComplainService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/complain")
public class ComplainController {
    @Autowired
    private ComplainService complainService;

    //得到用户的所有投诉信息
    @PostMapping("/getallbyuserid")
    public Result<List<Complain>> getallbyuserid(Integer userid){

        return Result.success(complainService.getallbyuserid(userid));
    }

    //添加投诉
    @PostMapping("/addcomplain")
    public Result addcomplain(@RequestBody Complain complain){
        complainService.addcomplain(complain);
        return Result.success();
    }

    //状态修改
    @PostMapping("/statechange")
    public Result statechange(Integer complainid,Integer state){
        complainService.statechange(complainid,state);
        return  Result.success();
    }

    //获得所有对应状态的投诉
    @PostMapping("/getstate")
    public Result<List<Complain>> getstate(String restaurantid,Integer state){
        return  Result.success(complainService.getstate(restaurantid,state));
    }

    @PostMapping("/accept")
    public  Result accept(@RequestBody Complain complain){
        complainService.accept(complain);
        return Result.success();
    }

    @PostMapping("/retry")
    public Result retry(@RequestBody Complain complain){
        complainService.retry(complain);
        return Result.success();
    }
    @PostMapping("/getByid")
    public Result<Complain> getByid(Integer complainid){
        return Result.success(complainService.getByid(complainid));
    }


}
